/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package visiodent;

import java.awt.Graphics;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.swing.JApplet;

/**
 *
 * @author hanhnv
 */
public class aSSVAPI extends JApplet {

    /**
     * Initialization method that will be called after the applet is loaded into
     * the browser.
     */
    @Override
    public void init() {
        // TODO start asynchronous download of heavy resources
        // add code into the applet itself, to specify that the extended
        // security privileges (gained by the applet’s signature) shall be transmitted to the
        // JavaScript code, too. This is done using an AccessController.doPrivileged block
        try
        {
            AccessController.doPrivileged(new PrivilegedExceptionAction()
            {
                @Override
                public Object run()
                {                    
                    
                    // dont forget to copy this dll into user.dir/dll/ of jri environment    
                    // in case of embbeding in web browser, this is web browser folder
                    // for example C:\Program Files (x86)\Mozilla Firefox\dll
                    System.load(System.getProperty("user.dir") + "/dll/assv.dll");                      
                    
                    // dont forget to copy this dll into lib/ext of jri environment      
                    //System.load(System.getProperty("java.home") + "/lib/ext/assv.dll"); 
                    
                    return null;
                }
            });
         } catch (PrivilegedActionException e)
         {
            // catch block
         }        
        
    }
    
    @Override
    public void paint(final Graphics g)
    {       
        try
        {
            AccessController.doPrivileged(new PrivilegedExceptionAction()
            {
                @Override
                public Object run()
                {                    
                    final aSSVAPI aSSV = new aSSVAPI();        
                    aSSV.ssvLireCartePS("CPS", "Vitale", "1234");
                    return null;
                }
            });
         } catch (PrivilegedActionException e)
         {
            // catch block
         }         
    }
    // TODO overwrite start(), stop() and destroy() methods
    private native String ssvLireCartePS(String NomRessourcePS, String NomRessourceLecteur, String CodePorteurPS);
    //private native String ssvLireDroitsVitale(String NomRessourcePS, String NomRessourceLecteur, String CodePorteurPS, String DateConsultation);
    
}
